package cn.tedu.basic;

import java.sql.*;

public class JdbcUtils3 {
    public static Connection getConnection() throws Exception {
        Class.forName("com.mysql.jdbc.Driver");
        String url="jdbc:mysql://localhost:3306/jdbctest?characterEncoding=utf8&useunicode=true";
        String name="root";
        String pwd="root";
        Connection con = DriverManager.getConnection(url, name, pwd);
        return con;

    }

    public static void close(Connection con, PreparedStatement ps, ResultSet rs) {
        if(con!=null) {
            try {
                rs.close();
            } catch (SQLException e) {
                e.printStackTrace();
            }finally {
                con=null;
            }
        }
        if(ps!=null) {
            try {
                ps.close();
            } catch (SQLException e) {
                e.printStackTrace();
            }finally {
                ps=null;
            }
        }
        if(ps!=null) {
            try {
                con.close();
            } catch (SQLException e) {
                e.printStackTrace();
            } finally{
                ps=null;
            }
        }
    }
}
